package com.coolw.design.pattern.behavior.liabilitychain.handler;

import com.coolw.design.pattern.behavior.liabilitychain.dto.OrderCheckParam;
import org.dromara.hutool.core.util.ObjUtil;

/**
 * 订单检查处理抽象类
 *
 * @author coolw
 * @date 2024/10/22 19:26
 */
public abstract class AbstractOrderCheckHandler implements OrderCheckHandler {

    private OrderCheckHandler nextOrderCheckHandler;

    /**
     * 执行订单检查
     *
     * @param orderCheckParam 订单检查参数
     */
    public abstract void doCheck(OrderCheckParam orderCheckParam);

    @Override
    public void check(OrderCheckParam orderCheckParam) {
        this.doCheck(orderCheckParam);

        if (ObjUtil.isNotNull(nextOrderCheckHandler)) {
            nextOrderCheckHandler.check(orderCheckParam);
        }
    }

    @Override
    public OrderCheckHandler nextHandler(OrderCheckHandler nextOrderCheckHandler) {
        this.nextOrderCheckHandler = nextOrderCheckHandler;
        return this.nextOrderCheckHandler;
    }
}
